package com.tools.cleanmaster.store;

import android.content.Context;
import android.content.SharedPreferences;

import com.hm.base.android.mob.store.SharedPrefManager;
import com.tools.cleanmaster.CleanApplication;
import com.tools.cleanmaster.CleanConstant;
import com.tools.cleanmaster.bean.AutoCleanFeature;

/**
 * desc:
 * date: 2018/4/16
 * author: ancun
 */

public class CleanSharedPrefManager extends SharedPrefManager {

    // 配置信息
    public static final String APP_PREF = "antivirus_config_pref";

    // 配置
    private SharedPreferences antivirusPref;

    public CleanSharedPrefManager(CleanApplication context) {
        super(context);
        antivirusPref = context.getSharedPreferences(APP_PREF, Context.MODE_PRIVATE);
    }

    /**
     * 设置开发者模式
     *
     * @param isOpen
     */
    public void setKeyOpenDeveloper(boolean isOpen) {
        antivirusPref.edit().putBoolean(CleanConstant.KEY_OPEN_DEVELOPER, isOpen).apply();
    }

    /**
     * 获取是否开启开发者模式
     *
     * @return
     */
    public boolean getKeyOpenDeveloper() {
        return antivirusPref.getBoolean(CleanConstant.KEY_OPEN_DEVELOPER, false);
    }

    public void setChargingEnable(boolean enable) {
        SharedPreferences.Editor editor = antivirusPref.edit();
        editor.putBoolean(CleanConstant.KEY_CHARGING_FUNC_ENABLE, enable).apply();
    }

    public boolean getChargingEnable() {
        return antivirusPref.getBoolean(CleanConstant.KEY_CHARGING_FUNC_ENABLE, false);
    }

    /**
     * 设置 闪屏页 -- 是否同意免责声明和隐私条款
     */
    public void setAgreeClause() {
        antivirusPref.edit().putBoolean(CleanConstant.KEY_SPLASH_AGREE_CLAUSE, true).apply();
    }

    /**
     * 获取 闪屏页 -- 是否同意免责声明和隐私条款
     *
     * @return
     */
    public boolean isAgreeClause() {
        return antivirusPref.getBoolean(CleanConstant.KEY_SPLASH_AGREE_CLAUSE, false);
    }


    /**
     * 自动清理开关
     *
     * @param feature
     * @return
     */
    public boolean isAutoCleanEnable(AutoCleanFeature feature) {
        return antivirusPref.getBoolean(CleanConstant.KEY_ENABLE_FEATURE + feature.key, false);
    }

    /**
     * 自动清理特性开关
     *
     * @param feature
     * @param isEnable
     */
    public void setAutoCleanEnable(AutoCleanFeature feature, boolean isEnable) {
        antivirusPref.edit().putBoolean(CleanConstant.KEY_ENABLE_FEATURE + feature.key, isEnable).apply();
    }

    /**
     * 自动清理频率
     *
     * @param hour
     */
    public void setAutoCleanFrequency(int hour) {
        antivirusPref.edit().putInt(CleanConstant.KEY_AUTO_CLEAN_FREQUENCY, hour).apply();
    }

    public int getAutoCleanFrequency() {
        return antivirusPref.getInt(CleanConstant.KEY_AUTO_CLEAN_FREQUENCY, 24);
    }

    /**
     * 自动清理 一共清理了多少cache
     *
     * @param size
     */
    public void setAutoCleanTotalSize(long size) {
        antivirusPref.edit().putLong(CleanConstant.KEY_AUTO_CLEAN_TOTAL_SIZE, size).apply();
    }

    public long getAutoCleanTotalSize() {
        return antivirusPref.getLong(CleanConstant.KEY_AUTO_CLEAN_TOTAL_SIZE, 0);
    }

    /**
     * 上一次 一共清理了多少cache
     *
     * @param size
     */
    public void setLastCleanTotalSize(long size) {
        antivirusPref.edit().putLong(CleanConstant.KEY_AUTO_CLEAN_LAST_SIZE, size).apply();
    }

    public long getLastCleanTotalSize() {
        return antivirusPref.getLong(CleanConstant.KEY_AUTO_CLEAN_LAST_SIZE, 0);
    }

    /**
     * 显示反馈提示对话框
     */
    public void showFeedbackDialog() {
        antivirusPref.edit().putBoolean(CleanConstant.KEY_SHOW_FEEDBACK_DIALOG, true).apply();
    }

    /**
     * 是否有显示过反馈提示对话框
     *
     * @return
     */
    public boolean haveShowedFeedbackDialog() {
        return antivirusPref.getBoolean(CleanConstant.KEY_SHOW_FEEDBACK_DIALOG, false);
    }

}
